package cn.itsource.basic.util;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 专门用来给前端返回信息的
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "交互信息对象")
public class AjaxResult {
    //成功失败大状态
    @ApiModelProperty(value = "true:成功,false:失败")
    private Boolean success = true;
    //提示信息
    @ApiModelProperty(value = "提示信息")
    private String message = "OK";
    //返回数据
    @ApiModelProperty(value = "数据载体")
    private Object data;
    //状态码
    @ApiModelProperty(value = "具体状态码")
    private String code = PetConstant.SYSTEM_SUCCESS; //魔法值

    /**
     * 返回成功,不携带数据给前端
     */
    public static AjaxResult createSuccess() {
        return new AjaxResult();
    }

    /**
     * 返回成功,要携带数据给前端
     */
    public static AjaxResult createSuccess(Object data) {
        return new AjaxResult(true, "OK", data, PetConstant.SYSTEM_SUCCESS);
    }

    /**
     * 返回错误
     */
    public static AjaxResult createError(String code, String message) {
        return new AjaxResult(false, message, null, code);
    }

    /**
     * 返回错误,错误码默认系统错误
     */
    public static AjaxResult createError(String message) {
        return createError(PetConstant.SYSTEM_ERROR, message);
    }


    public static void main(String[] args) {

        List<String> all = Arrays.asList(
                "蔡熊",
                "吴裕祺",
                "伍茂盛",
                "李乘龙",
                "王康",
                "邹雄",
                "钱天胜",
                "鲁俊杰",
                "蒋帅",
                "游鸿星",
                "周院梦钊",
                "贺运涛",
                "程志鹏",
                "陈雄",
                "张业锋",
                "范志熠",
                "朱恺燚",
                "徐小龙",
                "朱柱胜",
                "张明卓",
                "占祺",
                "柯凯",
                "卫松",
                "褚旭",
                "何梓丰",
                "刘可",
                "张灿帮",
                "廖奋",
                "肖子健",
                "尹博",
                "肖永晨",
                "刘佳杰",
                "杨志峰",
                "黄永恒",
                "李胡焕",
                "程文博",
                "杨泽鑫",
                "袁野",
                "陈绪兵",
                "杨志新",
                "李嘉俊",
                "杨梓星");

        ArrayList<JavaBean> objects = new ArrayList<>();


        for (String s : all) {

            JavaBean javaBean = new JavaBean();

            String s1 = RandomUtil.randomNumbers(1);
            int i = Integer.parseInt(s1);

            javaBean.setGender(i%2==0?0:1);
            javaBean.setName(s);

            objects.add(javaBean);
        }


        String s = JSONObject.toJSONString(objects);

        System.out.println(s);

    }
}
